#include <types.h>
#include <Debug.h>
#include <FrameAllocator.h>
#include <Kernel.h>
#include <IDT.h>
#include <IRQ.h>
#include <Multiboot.h>
#include <Paging.h>
#include <PIT.h>

void TextPanic(const char *str) {
	byte attr = 0x0F;
	short *vm = (short *) 0xB8000;
	for (int i = 0; i < 80 * 25; i++) {
		vm[i] = 0;
	}
	int i = 0;
	while (*str) {
		vm[i] = *str | attr << 8;
		i++;
		str++;
	}
	
	asm volatile ("CLI\nHLT");
}

extern "C" void entry(void *mbh, dword magic) {
	if (magic != 0x2BADB002) {
		TextPanic("The bootloader is not a valid multiboot compliant loader");
	}

	FrameAllocator::Init();
	CPU::ReadInfo();
	Multiboot::Init(mbh);
	IDT::Init();
	IRQ::Init();
	PIT::Init();

	asm volatile ("STI");

	Paging::Init();
	
	Kernel::Start();
}
